<template>
  <div>
    <!--    &lt;!&ndash; 搜索栏   &ndash;&gt;-->
    <!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="82px">-->

    <!--&lt;!&ndash;      <el-form-item label="省编号" prop="pid">&ndash;&gt;-->
    <!--&lt;!&ndash;        <el-input&ndash;&gt;-->
    <!--&lt;!&ndash;          v-model="queryParams.pid"&ndash;&gt;-->
    <!--&lt;!&ndash;          size="mini"&ndash;&gt;-->
    <!--&lt;!&ndash;          clearable&ndash;&gt;-->
    <!--&lt;!&ndash;          placeholder="请输入名称"&ndash;&gt;-->
    <!--&lt;!&ndash;          label-width="100px"&ndash;&gt;-->
    <!--&lt;!&ndash;          @keyup.enter.native="handleQuery"&ndash;&gt;-->
    <!--&lt;!&ndash;        ></el-input>&ndash;&gt;-->
    <!--&lt;!&ndash;      </el-form-item>&ndash;&gt;-->
    <!--      <el-form-item label="地区编号" prop="locationId">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.locationId"-->
    <!--          size="mini"-->
    <!--          clearable-->
    <!--          placeholder="请输入名称"-->
    <!--          label-width="100px"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        ></el-input>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="省名称" prop="provinceName">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.provinceName"-->
    <!--          size="mini"-->
    <!--          clearable-->
    <!--          placeholder="请输入名称"-->
    <!--          label-width="100px"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        ></el-input>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="省简称" prop="provinceShortName">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.provinceShortName"-->
    <!--          size="mini"-->
    <!--          clearable-->
    <!--          placeholder="请输入名称"-->
    <!--          label-width="100px"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        ></el-input>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="城市名称" prop="cityName">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.cityName"-->
    <!--          size="mini"-->
    <!--          clearable-->
    <!--          placeholder="请输入名称"-->
    <!--          label-width="100px"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        ></el-input>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="日期" prop="dateTimeStr">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.dateTimeStr"-->
    <!--          size="mini"-->
    <!--          clearable-->
    <!--          placeholder="请输入日期"-->
    <!--          label-width="100px"-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        ></el-input>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="地区类型" prop="cityType">-->
    <!--        <el-select-->
    <!--          v-model="queryParams.cityType"-->
    <!--          placeholder="请选择地区类型"-->
    <!--          size="mini"-->
    <!--          @change="handleQuery"-->
    <!--        >-->
    <!--          <el-option label="省份" value=2></el-option>-->
    <!--          <el-option label="城市" value=1></el-option>-->
    <!--        </el-select>-->
    <!--      </el-form-item>-->
    <!--      <el-form-item>-->
    <!--        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
    <!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
    <!--      </el-form-item>-->
    <!--    </el-form>-->
    <!--    &lt;!&ndash; 搜索栏   &ndash;&gt;-->

    <!-- 搜索栏   -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="82px">
      <el-form-item label="地区编号" prop="locationId">
        <el-input
          v-model="queryParams.locationId"
          size="mini"
          clearable
          placeholder="请输入名称"
          label-width="100px"
          @keyup.enter.native="handleQuery"
        ></el-input>
      </el-form-item>
      <el-form-item label="省名称" prop="provinceName">
        <el-input
          v-model="queryParams.provinceName"
          size="mini"
          clearable
          placeholder="请输入名称"
          label-width="100px"
          @keyup.enter.native="handleQuery"
        ></el-input>
      </el-form-item>
      <el-form-item label="省简称" prop="provinceShortName">
        <el-input
          v-model="queryParams.provinceShortName"
          size="mini"
          clearable
          placeholder="请输入名称"
          label-width="100px"
          @keyup.enter.native="handleQuery"
        ></el-input>
      </el-form-item>
      <el-form-item label="日期" prop="dateTimeStr">
        <el-date-picker
          v-model="queryParams.dateTimeStr"
          type="date"
          size="mini"
          clearable
          label-width="100px"
          @keyup.enter.native="handleQuery"
          value-format="yyyy-MM-dd"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 搜索栏   -->

    <!-- 新增 导出按钮操作   -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handlExport"

        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getProviceList"></right-toolbar>
    </el-row>
    <!-- 新增 导出按钮操作   -->

    <!-- 列表数据   -->
    <el-table v-loading="loading" :data="covidProviceRecordList">
      <el-table-column label="地区编号" width="110" align="center" prop="locationId"/>
      <el-table-column label="省名称" width="110" align="center" prop="provinceName"/>
      <el-table-column label="省简称" width="110" align="center" prop="provinceShortName"/>
      <el-table-column label="日期" width="110" align="center" prop="dateTimeStr"/>
      <el-table-column label="地区类型" width="110" align="center" prop="cityType">
        <template slot-scope="scope">
          <span v-if="scope.row.cityType == 1">城市</span>
          <span v-if="scope.row.cityType == 2">省份</span>
        </template>
      </el-table-column>
      <el-table-column label="现存确诊" width="110" align="center" prop="currentConfirmedCount"/>
      <el-table-column label="累计确诊" width="110" align="center" prop="confirmedCount"/>
      <el-table-column label="治愈数量" width="110" align="center" prop="curedCount"/>
      <el-table-column label="死亡数量" width="110" align="center" prop="deadCount"/>
      <el-table-column label="疑似数量" width="110" align="center" prop="suspectedCount"/>
      <el-table-column label="创建时间" align="center" prop="createTime"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleCityList(scope.row)"
          >详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 列表数据   -->


    <!-- 分页   -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.page"
      :limit.sync="queryParams.perPage"
      @pagination="getProviceList"
    />
    <!-- 分页   -->
  </div>
</template>

<script>
import {listProviceCovid,listCityCovid} from "@/api/covid/index";

export default {
  name: "index",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 疫情数据记录表格数据
      covidProviceRecordList: [],
      ovidCityRecordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        page: 1,
        perPage: 10,
        orderBy: 'current_confirmed_count desc',
        locationId: null,
        provinceName: null,
        provinceShortName: null,
        dateTimeStr: null
      },
      queryCityParams: {
        orderBy: 'location_id asc',
        locationId: null,
        dateTimeStr: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}

    }
  },
  created() {
    this.getProviceList()
  },
  methods: {
    /** 查询省份疫情数据列表 */
    getProviceList() {
      let date = this.queryParams.dateTimeStr
      if (date) {
        this.queryParams.dateTimeStr = date
      } else {
        this.queryParams.dateTimeStr = this.formatDate(new Date(), 'yyyy-MM-dd')
      }
      this.loading = true
      listProviceCovid(this.queryParams).then(response => {
        this.covidProviceRecordList = response.data.data.dataList
        this.total = response.data.data.count
        this.loading = false
      })
    },

    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },

    // 表单重置
    reset() {
      this.form = {
        id: null,
        pageNum: 1,
        perPage: 50,
        pid: null,
        locationId: null,
        provinceName: null,
        provinceShortName: null,
        cityName: null,
        dateTimeStr: null,
        cityType: null,
        currentConfirmedCount: null,
        confirmedCount: null,
        curedCount: null,
        deadCount: null,
        suspectedCount: null,
        createTime: null
      }
      this.resetForm('form')
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.page = 1
      this.getProviceList()
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },

    /** 详情按钮 */
    handleCityList(row) {
      this.reset();
      this.queryCityParams.locationId = row.locationId;
      this.queryCityParams.dateTimeStr = this.queryParams.dateTimeStr;
      listCityCovid(this.queryCityParams).then(response => {
        this.ovidCityRecordList = response.data.data.dataList;
      });
    },

    // 日期格式化
    formatDate(value, args) {
      var dt = new Date(value);
      let year = dt.getFullYear();
      let month = (dt.getMonth() + 1).toString().padStart(2, '0');
      let date = dt.getDate().toString().padStart(2, '0');
      return `${year}-${month}-${date}`;
    }

  }
}
</script>

<style scoped>

</style>
